package com.piao.springboot_jdbc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 整合基本JDBC
 */
@Controller
public class JdbcController {

    @Autowired
    JdbcTemplate jdbcTemplate;

    //存储预返回页面的结果对象
    private Map<String, Object> result;


    @ResponseBody
    @GetMapping("/findAllWord")
    public Map<String, Object> findAllWord() {
        result = new HashMap<>();
        List<Map<String, Object>> mapList= jdbcTemplate.queryForList("SELECT ENGLISH,CHINESE FROM word");
        result.put("data",mapList);
        return result;
    }

}
